﻿using APP.IO;
using APP.OpenCV;
using MinesweeperAutoScanDemo.Model;
using NotifyPropertyBase;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MinesweeperAutoScanDemo.ViewModel
{
    public class PictureColorRangeViewModel : ViewModelBase
    {




        public PictureColorRangeViewModel()
        {
            Init();



            //MeanStdDev 查看均值 

            //80以下  识别出来就是 数字 识别不出来 就是0 

            //蓝色一般在 80以上 


            // 再  使用均值  前后 +- 10个单位 查找颜色。

        }




        public void Init()
        {
           
            string imageFolder = PathHelper.GetPath(FolderType.Temp, "ImageNotRecognize");
            //string imageFolder = @"C:\Users\Administrator\Documents\MyAPP\Temp\ImageNotRecognize\";
            var files = new DirectoryInfo(imageFolder).GetFiles();
            List<ImageColorModel> list = new List<ImageColorModel>();
            foreach (var file in files)
            {
                var temp = new ImageColorModel();
                temp.ImagePath = file.FullName;
                OpenCVHelper.GetImageColorRange(file.FullName, out Color minHSV, out Color maxHSV, out Color minRGB, out Color maxRGB, out Color mean, out Color stdde);
                temp.MinRGB = minRGB;
                temp.MaxRGB = maxRGB;
                temp.MinHSV = minHSV;
                temp.MaxHSV = maxHSV;

                temp.MeanColor = mean;
                temp.MeanHSV = stdde;
                temp.MeanBrush = new SolidBrush(mean);
                list.Add(temp);
            }
            TestImagesSource = new ObservableCollection<ImageColorModel>(list);
        }

        private ObservableCollection<ImageColorModel> _TestImagesSource;
        public ObservableCollection<ImageColorModel> TestImagesSource { get => _TestImagesSource; set => Set(ref _TestImagesSource, value); }

        public RelayCommand SelectFolderCommand { get; set; }

    }
}
